/**
 * 复印/打印记录页面 js
 * @author [song cheng lin]
 */

  $(function(){
  	//获取出院科室
  	$("#CopyPrintRecord_Dept").combobox({
  		url:ctx + "/Print/getDept",
  		valueField:"ftykh",
  		textField:"fksname",
  		width:120, 
  		height:24,
  		queryParams :{
  			"fcode" : sysFcode
  		},
  		onLoadSuccess : function() {
  			$('#CopyPrintRecord_Dept').combobox('select', 'TZYQY');
  		},
  		onSelect : function(record){
  			//var code = record.ftykh;
  		}
  	});
  	
  	//获取操作员
  	$("#CopyPrintRecord_fczy").combobox({
  		url:ctx + "/Print/getZzDoc",
  		valueField:"fzzdoctbh",
  		textField:"fzzdoct",
  		width:120, 
  		height:24
  	});

	 //诊断类型名称()
	$('#CopyPrintRecord_query-template').combobox({
	 	width : 120,
	 	height:24,
 		panelHeight : 60,
 		valueField : 'id',
 		textField : 'text',
 		data : [{'id': 'FCADATE','text': '复印申请日期'},{'id': 'FCYDATE','text': '出院日期'}],
 		onLoadSuccess:function(data){
 			$('#CopyPrintRecord_query-template').combobox('select',data[0].id);
 		}
	 })
	 
  	 //状态()
	$('#CopyPrintRecord_fstate').combobox({
	 	width : 120,
	 	height:24,
 		panelHeight : 200,
 		valueField : 'id',
 		textField : 'text',
 		data : [{'id': '0','text': '全部(多选)'},{'id': '1','text': '未申请'},{'id': '2','text': '已申请'},
 			    {'id': '3','text': '未收费'},{'id': '4','text': '已收费'},{'id': '5','text': '未打印'},
 			    {'id': '6','text': '已打印'}],
 		onLoadSuccess:function(data){
 			$('#CopyPrintRecord_fstate').combobox('select',data[0].id);
 		}
	 })
  		//加载数据表格
  		$("#CopyPrintRecordGrid").datagrid({
  			url:'',
  			toolbar:"#CopyPrintRecordBar",
  			fitColumns:true,
  			border : false,
  			striped : true,
  			fit : true,
  			singleSelect: true,
  			pagination : true,
  			//autoScroll : true,
  			pageSize : 20,
  			pageList : [ 20, 30,50 ],
  			columns:[[
				{field:'FID',title:'ID',width:0,align:'center',hidden:true},	
				{field:'opretion',title:'操作',width:80,align:'center',
			    	formatter:function(value,row,index){
			    		
			    		if(row.status == 1){
			    			return "<button class='shootBtn' onclick='CopyPrintRecordPrint("+index+");'>打印</button>";
			    		}else if (row.status == 2) {
			    			return "<button class='shootBtn' onclick='CopyPrintRecordRegister("+index+");'>登记</button>";
			    		}else if (row.status == 3) {
			    			return "<button class='shootBtn' onclick='CopyPrintRecordPrintCharge("+index+");'>收费</button>";
			    		}
			    		return "";
			    	}
			    },  
			    {field:'fregister',title:'已登记',width:80,align:'center',
			    	formatter:function(value,row,index){
			    		if(row.fzt == 1){
			    			return "<sapn>是</span>";
			    		}
			    		return "";
			    	}	
			    },
			    {field:'fcharge',title:'已收费',width:80,align:'center',
			    	formatter:function(value,row,index){
			    		if(row.fzt == 1){
			    			return "<sapn>是</span>";
			    		}
			    		return "";
			    	}	
			    },
			    {field:'fprint',title:'已打印',width:80,align:'center',
			    	formatter:function(value,row,index){
			    		if(row.fzt == 1){
			    			return "<sapn>是</span>";
			    		}
			    		return "";
			    	}	
			    },
			    {field:'location',title:'类型',width:80,align:'center',
			    	formatter:function(value,row,index){
			    		if(row.fzt == 1){
			    			return "<sapn>打印</span>";
			    		}else if (row.fzt == 2) {
			    			return "<sapn>复印</span>";
			    		}
			    		return "";
			    	}	
			    },  
  	            {field:'fsqdate',title:'申请日期',width:120,align:'center',
  					formatter:function(value){
  						if($("#CopyPrintRecord_Date1").datebox("getValue") == ''){
  							return new Date().format("yyyy-MM-dd");
  						}else{
  							return $("#CopyPrintRecord_Date1").datebox("getValue");
  						}
  						
  					}
  				},  
  				{field:'fsfdate',title:'收费日期',width:120,align:'center',
  					formatter:function(value){
  						if($("#CopyPrintRecord_Date1").datebox("getValue") == ''){
  							return new Date().format("yyyy-MM-dd");
  						}else{
  							return $("#CopyPrintRecord_Date1").datebox("getValue");
  						}
  					}
  				}, 
  				{field:'fsqrname',title:'申请人',width:90,align:'center' },
  				{field:'fneedtomail',title:'是否邮寄',width:100,align:'center',
			    	formatter:function(value,row,index){
			    		if(row.fzt == 1){
			    			return "<sapn>是</span>";
			    		}
			    		return "";
			    	}	
			    },
			    {field:'fname',title:'患者姓名',width:100,align:'center'},
  				{field:'fprn',title:'病案号',width:100,align:'center'},
  				{field:'fcydate',title:'出院日期',width:120,align:'center',
  					formatter:function(value){
  						return new Date(value).format("yyyy-MM-dd");
  					}
  				}, 
  				{field:'fsex',title:'性别',width:60,align:'center' }, 
  				{field:'fage',title:'年龄',width:60,align:'center' }, 
  				{field:'fcydept',title:'出院科室',width:120,align:'center' },
  				{field:'fcydept',title:'出院病区',width:120,align:'center' },
  				{field:'fzzdoct',title:'主治医生',width:100,align:'center' },   				 
  				{field:'fbarcode',title:'条码号',width:120,align:'center' }   				
  			       ]],
  			    onLoadSuccess:function(data){/*
  			    	if(data){
  			    		$.each(data.rows,function(index,item){
  			    			$('#CopyPrintRecordGrid').datagrid('checkRow',index);
  			    		});
  			    	}
  			    */}   
  		});
  	});
  

  //查询
  	function CopyPrintRecordSearch(){
  		var FCYDATE = $("#CopyPrintRecord_query-template").datebox("getValue");
  		var FQSDATE = $("#CopyPrintRecord_Date1").datebox("getValue");
  		var FJSDATE = $("#CopyPrintRecord_Date2").datebox("getValue");
  		var FCYKS = $("#CopyPrintRecord_Dept").combobox("getValue");
  		var FCZY = $("#CopyPrintRecord_fczy").textbox("getValue");
  		var FPRNTEXT = $("#CopyPrintRecord_Fprn").textbox("getValue");
  		var FNAME = $("#CopyPrintRecord_Name").textbox("getValue");
  		var FSTATE = $("#CopyPrintRecord_fstate").numberbox("getValue");
  		
  		$("#CopyPrintRecordGrid").datagrid({
  			url:ctx + "/Print/copyPrintRecordSearch",
  			queryParams:{
  				"FCYDATE" : FCYDATE,
  				"FQSDATE" : FQSDATE,
  				"FJSDATE" : FJSDATE,
  				"FCYKS" : FCYKS,
  				"FCZY" : FCZY,
  				"FPRNTEXT" : FPRNTEXT,
  				"FNAME" : FNAME,
  				"FSTATE" : FSTATE
  			}
  		});
  	
  	 	
  	 }

  	//打开快速打印页面
  	function openRegister(index){
  		var rows = $("#CopyPrintRecordGrid").datagrid("getRows")[index];
  		var fcydate = new Date(rows.fcydate).format("yyyy-MM-dd");
  		var frydate = new Date(rows.frydate).format("yyyy-MM-dd");
  		var url = ctx + "/Print/CopyPrint?fprn="+rows.fprn+"&fzyid="+rows.fzyid+"&fcydate="+fcydate+"&frydate="+frydate+
  					"&fcydept="+encodeURI(encodeURI(rows.fcydept))+"&fcybs="+encodeURI(encodeURI(rows.fcybs))+"&fname="+encodeURI(encodeURI(rows.fname))+"&fidcard="+rows.fidcard
  					+"&ftimes="+rows.ftimes+"&fsex="+encodeURI(encodeURI(rows.fsex));
  		addTab("打印登记", url,"", false);
  		/* var tabPanel = $('#tabs');
  		tabPanel.tabs('close',"打印登记查询"); */
  	}
